{# Copyright The IETF Trust 2015, All Rights Reserved #}
{% load origin %}
{% origin %}
{% load widget_tweaks %}
{% load ietf_filters %}
{% load ballot_icon %}
{% load person_filters %}
{% load django_bootstrap5 %}
<tr {% if color_ad_position %}{% with doc|ballotposition:user as pos %}{% if pos %}class="position-{{ pos.slug }}-row"{% endif %}{% endwith %}{% endif %}>
    <td class="bg-transparent">
        {% if user.is_authenticated %}
            <a href="{% url "ietf.community.views.untrack_document" email_or_name=request.user.username name=doc.name %}"
               class="track-untrack-doc {% if not doc.tracked_in_personal_community_list %}d-none{% endif %}"
               aria-label="Remove from your personal I-D list"
               title="Remove from your personal I-D list">
                <i class="bi bi-bookmark-check-fill"></i>
            </a>
            <a href="{% url "ietf.community.views.track_document" email_or_name=request.user.username name=doc.name %}"
               class="track-untrack-doc {% if doc.tracked_in_personal_community_list %}d-none{% endif %}"
               aria-label="Add to your personal I-D list"
               title="Add to your personal I-D list">
                <i class="bi bi-bookmark"></i>
            </a>
            <br>
        {% endif %}
        {% if user.person.review_teams %}
            <a class="review-wish-add-remove-doc ajax {% if not doc.has_review_wish %}d-none{% endif %}"
               href="{% url "ietf.doc.views_review.review_wishes_remove" name=doc.name %}?next={{ request.get_full_path|urlencode }}"
               aria-label="Remove from your review wishes for all teams"
               title="Remove from your review wishes for all teams">
                <i class="bi bi-chat-left-heart-fill"></i>
            </a>
            <a class="review-wish-add-remove-doc {% if user.person.review_teams|length_is:"1" %}ajax {% endif %} {% if doc.has_review_wish %}d-none{% endif %}"
               href="{% url "ietf.doc.views_review.review_wish_add" name=doc.name %}?next={{ request.get_full_path|urlencode }}"
               aria-label="Add to your review wishes"
               title="Add to your review wishes">
                <i class="bi bi-chat-left-heart"></i>
            </a>
            <br>
        {% endif %}
        {% for session in doc.sessions %}
            <a href="{% url 'ietf.meeting.views.agenda_ical' num=session.meeting.number session_id=session.id %}"
               title="Calendar entry: document is on the agenda for {{ session.group.acronym }}@{{ session.meeting }}">
                <i class="bi bi-calendar"></i>
            </a>
        {% endfor %}
    </td>
    <td class="doc bg-transparent">
        {% if doc.pages %}<small class="float-end text-body-secondary d-none d-sm-block">{{ doc.pages }} page{{ doc.pages|pluralize }}</small>{% endif %}
        <div>
            <a href="{{ doc.get_absolute_url }}">
                {% if doc.type_id == "rfc" %}
                    RFC {{ doc.rfc_number }}
                {% else %}
                    {{ doc.name }}-{{ doc.rev }}
                {% endif %}
            </a>
{#            {% if doc.type_id == "rfc" and "draft" in doc.name %}<i class="text-body-secondary">(was {{ doc.name }})</i>{% endif %} TODO drop this or look up the corresponding draft name#}
            <br>
            {% comment %}
            <div class="float-end">
                {% for check in doc.submission.latest_checks %}
                    {% if check.passed != None and check.symbol.strip %}
                        {% if check.errors or check.warnings %}
                            <a href="#"
                               class="text-decoration-none checker-warning"
                               data-bs-toggle="modal"
                               data-bs-target="#check-{{ check.pk }}"
                               title="{{ check.checker|title }} returned warnings or errors.">
                                {{ check.symbol|safe }}
                            </a>
                        {% else %}
                            <a href="#"
                               class="text-decoration-none checker-success"
                               data-bs-toggle="modal"
                               data-bs-target="#check-{{ check.pk }}"
                               title="{{ check.checker|title }} passed">
                                {{ check.symbol|safe }}
                            </a>
                        {% endif %}
                        {% include "doc/yang-check-modal-overlay.html" %}
                    {% endif %}
                {% endfor %}
            </div>
            {% endcomment %}
            <b>{{ doc.title }}</b>
            {% if doc.has_verified_errata %}
                <a class="badge rounded-pill text-bg-danger text-decoration-none float-end"
                   href="https://www.rfc-editor.org/errata_search.php?rfc={{ doc.rfc_number }}">
                    Errata
                </a>
            {% elif doc.has_errata %}
                <a class="badge rounded-pill text-bg-warning text-decoration-none float-end"
                   href="https://www.rfc-editor.org/errata_search.php?rfc={{ doc.rfc_number }}">
                    Errata
                </a>
            {% endif %}
        </div>
        {% if user|has_role:"Secretariat" and doc.reschedule_form %}
            <div class="mt-3">
                {% bootstrap_form doc.reschedule_form layout="floating" exclude="clear_returning_item, show_clear" %}
                {% if doc.reschedule_form.show_clear %}
                    {% bootstrap_field doc.reschedule_form.clear_returning_item %}
                {% endif %}
            </div>
        {% endif %}
    </td>
    <td class="bg-transparent">
        {% if doc.latest_revision_date|timesince_days|new_enough:request and doc.type_id != "rfc" %}
            {% if doc.rev != "00" %}
                <a href="{{ rfcdiff_base_url }}?url2={{ doc.name }}-{{ doc.rev }}">
            {% elif doc.replaces %}
                {% with first_replaces=doc.replaces|first %}
                    <a href="{{ rfcdiff_base_url }}?url1={{ first_replaces.name }}&amp;url2={{ doc.name }}-{{ doc.rev }}">
                {% endwith %}
            {% endif %}
        {% endif %}
        {% if doc.type_id == "rfc" %}
            {{ doc.latest_revision_date|date:"Y-m" }}
        {% else %}
            {{ doc.latest_revision_date|date:"Y-m-d" }}
        {% endif %}
        {% if doc.latest_revision_date|timesince_days|new_enough:request and doc.type_id != "rfc" %}
            {% if doc.rev != "00" or doc.replaces %}</a>{% endif %}
        {% endif %}
        {% if doc.latest_revision_date|timesince_days|new_enough:request %}
            <br>
            <div class="float-end">
                <span class="badge rounded-pill text-bg-success">New</span>
            </div>
        {% endif %}
        {% if doc.get_state_slug == "active" and doc.expirable and doc.expires|timesince_days|expires_soon:request %}
            <br>
            <span class="badge rounded-pill text-bg-warning">Expires soon</span>
        {% endif %}
    </td>
    {% include "doc/search/status_columns.html" %}
    <td class="text-center d-none d-sm-table-cell bg-transparent">
        {% if doc.related_ipr %}
            <a href="{% url "ietf.ipr.views.search" %}?submit=draft&amp;id={{ doc.name }}">
                <span class="badge rounded-pill text-bg-info">{{ doc.related_ipr|length }}</span>
            </a>
        {% endif %}
    </td>
    {% if show_ad_and_shepherd %}
        <td class="d-none d-sm-table-cell bg-transparent">
            {% if doc.ad %}
                {% person_link doc.ad title="Area Director" %}
            {% endif %}
            <br>
            {% if doc.shepherd %}
                {% email_person_link doc.shepherd title="Shepherd" class="small text-body-secondary" %}
            {% endif %}
        </td>
    {% endif %}
</tr>
